<?php

class Menu extends CWidget {

    public function run() {
        $types = "'category', 'brand', 'sp_type'";
        $sql = 'select * from {{characs}} where ch_type in(' . $types . ')';
        $models = Yii::app()->db->getCommandBuilder()->createSqlCommand($sql)->queryAll();
        foreach ($models as $model) {
            if ($model['ch_type'] == 'category') {
                $rows[$model['ch_id']]['title'] = $model['ch_title'];
                $rows[$model['ch_id']]['url'] = $model['ch_url'];
            }
            if ($model['ch_type'] == 'brand') {
                $rows[$model['ch_category']]['brands'][] = $model;
            } elseif ($model['ch_type'] == 'sp_type') {
                $rows[$model['ch_category']]['sp_type'][] = $model;
            }
        }
//        echo '<pre>';
//        print_r($rows);
//        exit;        
        $pathUrl = !empty(Yii::app()->request->pathInfo) ? explode('/', Yii::app()->request->pathInfo) : 0;
        $this->render('menu', array('rows' => $rows, 'pathUrl' => $pathUrl));
    }

}
